//
//  XZChooseSexView.m
//  Teecloud
//
//  Created by 贵州贵农网络科技有限公司 on 2018/7/16.
//  Copyright © 2018年 小志. All rights reserved.
//

#import "XZChooseSexView.h"

@interface XZChooseSexView ()
@property (weak, nonatomic) IBOutlet UIView *maleView;
@property (weak, nonatomic) IBOutlet UIView *femaleView;

@property (weak, nonatomic) IBOutlet UIButton *maleButton;
@property (weak, nonatomic) IBOutlet UIButton *femaleButton;

@end

@implementation XZChooseSexView
- (void)awakeFromNib{
    [super awakeFromNib];
    UITapGestureRecognizer *maleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(maleViewTapClick)];
    [self.maleView addGestureRecognizer:maleTap];
    
    UITapGestureRecognizer *femaleTap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(femaleTapClick)];
    [self.femaleView addGestureRecognizer:femaleTap];
}
- (void)setSexName:(NSString *)sexName{
    if ([sexName isEqualToString:@"男"]) {
        [self.maleButton setImage:[UIImage imageNamed:@"choose"] forState:UIControlStateNormal];
        [self.femaleButton setImage:[UIImage imageNamed:@"unchoose"] forState:UIControlStateNormal];
    }else if ([sexName isEqualToString:@"女"]){
        [self.femaleButton setImage:[UIImage imageNamed:@"choose"] forState:UIControlStateNormal];
        [self.maleButton setImage:[UIImage imageNamed:@"unchoose"] forState:UIControlStateNormal];
    }
}
- (void)show{
    [UIView animateWithDuration:0.25 animations:^{
        UIWindow *rootView = [UIApplication sharedApplication].keyWindow;
        [rootView addSubview:self];
    }];
}
- (void)hide{
    [UIView animateWithDuration:0.25 animations:^{
        [self removeFromSuperview];
    }];
}
//男
- (void)maleViewTapClick{
    [self.maleButton setImage:[UIImage imageNamed:@"choose"] forState:UIControlStateNormal];
    [self.femaleButton setImage:[UIImage imageNamed:@"unchoose"] forState:UIControlStateNormal];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (self.delegate && [self.delegate respondsToSelector:@selector(chooseView:info:)]) {
            [self.delegate chooseView:self info:@{
                                                  @"key":@"男",
                                                  @"value":@"男"
                                                  }];
        }
    });
}
//女
- (void)femaleTapClick{
    [self.femaleButton setImage:[UIImage imageNamed:@"choose"] forState:UIControlStateNormal];
    [self.maleButton setImage:[UIImage imageNamed:@"unchoose"] forState:UIControlStateNormal];
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        if (self.delegate && [self.delegate respondsToSelector:@selector(chooseView:info:)]) {
            [self.delegate chooseView:self info:@{
                                                  @"key":@"女",
                                                  @"value":@"女"
                                                  }];
        }
    });
}
- (IBAction)cancleButtonClick:(UIButton *)sender {
    if (self.block) {
        self.block();
    }
    
}

@end
